package edu.pitt.cs.cs2410pj2.util;
/**
 * Process the address
 * @author zhangfan
 *
 */
public class AddrProcessor {
	/**
	 * process the address
	 * @param blockAddr
	 * @param p tiles
	 * @param n cache size
	 * @param a associativity
	 * @param b block size
	 * @return
	 */
	public static AddrInfo processAddr(String blockAddr,int p,int n,int a,int b) {
		AddrInfo info = new AddrInfo();
		String byteTile = ByteStrOperator.getByteFromHex(blockAddr, 12, 12+p-1);
		int tile = ByteStrOperator.byteStrToDec(byteTile);
		info.setTileId(tile);
		
		String byteSet = ByteStrOperator.getByteFromHex(blockAddr, b, n-a-1);
		int setIndex = ByteStrOperator.byteStrToDec(byteSet);
		info.setSetIndex(setIndex);
		
		String tag = ByteStrOperator.getByteFromHex(blockAddr, n-a, 31);
		int cacheTag = ByteStrOperator.byteStrToDec(tag);
		info.setCacheTag(cacheTag);
		//process the blockAddr
		return info;
	}
	

	
	public static void main(String[] args) {
		AddrInfo infor = processAddr("0x00000320",2, 6, 3, 2);
		
		System.out.println("Tile:"+infor.getTileId());
		System.out.println("setIndex:"+infor.getSetIndex());
		System.out.println("cacheTag:"+infor.getCacheTag());
		
	}
}
